﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gestion.Common.Extensions
{
    public static class EnumerableExtension
    {
        public static bool IsEmpty<T>(this IEnumerable<T> source)
        {
            return source == null || !source.GetEnumerator().MoveNext();
        }

        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            if (source != null && action != null)
                foreach (var item in source)
                    action(item);
        }

        public static void ForEach<T>(this IEnumerable<T> source, Action<T, int> action)
        {
            var index = 0;
            if (source != null && action != null)
                foreach (var item in source)
                    action(item, index++);
        }
    }
}
